package org.lmj.dim.po;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ServerResponse<T> {
    //成功
    public static final Integer SUCCESS=0;
    //错误的请求参数
    public static final Integer BAD_PARAMETER=400;
    //内部错误
    public static final Integer INNER_ERROR=500;
    //无权限
    public static final Integer UNAUTH=403;
    /**未登录、登录超时*/
    public static final Integer UNLOGIN=401;

    private Integer errcode;
    private String errmsg;
    private T data;

    public static <T> ServerResponse<T> success(T data) {
        return success(0,data);
    }

    public static <T> ServerResponse<T> success() {
        ServerResponse<T> response = new ServerResponse<T>();
        response.setErrcode(ServerResponse.SUCCESS);
        response.setErrmsg("success");
        return response;
    }

    public static <T> ServerResponse<T> success(int status, T data) {
        ServerResponse<T> response = new ServerResponse<T>();
        response.setErrcode(ServerResponse.SUCCESS);
        response.setErrmsg("success");
        response.setData(data);
        //log.info("请求返回报文为：{}", response.toString());
        return response;
    }

    public static <T> ServerResponse<T> success(int status, String msg, T data) {
        ServerResponse<T> response = new ServerResponse<T>();
        response.setErrcode(ServerResponse.SUCCESS);
        response.setData(data);
        response.setErrmsg(msg);
        //log.info("请求返回报文为：{}", response.toString());
        return response;
    }

    public static <T> ServerResponse<T> fail(int status, String msg) {
        ServerResponse<T> response = new ServerResponse<T>();
        response.setErrcode(status);
        response.setErrmsg(msg);
        //log.info("请求返回报文为：{}", response.toString());
        return response;
    }
}
